package com.wetest.uia2.stub;

import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.UiSelector;
import java.util.regex.Pattern;

/* loaded from: classes9.dex */
public class Selector {
    public static final long MASK_CHECKABLE = 1024;
    public static final long MASK_CHECKED = 2048;
    public static final long MASK_CLASSNAME = 16;
    public static final long MASK_CLASSNAMEMATCHES = 32;
    public static final long MASK_CLICKABLE = 4096;
    public static final long MASK_DESCRIPTION = 64;
    public static final long MASK_DESCRIPTIONCONTAINS = 128;
    public static final long MASK_DESCRIPTIONMATCHES = 256;
    public static final long MASK_DESCRIPTIONSTARTSWITH = 512;
    public static final long MASK_ENABLED = 32768;
    public static final long MASK_FOCUSABLE = 65536;
    public static final long MASK_FOCUSED = 131072;
    public static final long MASK_INDEX = 8388608;
    public static final long MASK_INSTANCE = 16777216;
    public static final long MASK_LONGCLICKABLE = 8192;
    public static final long MASK_PACKAGENAME = 524288;
    public static final long MASK_PACKAGENAMEMATCHES = 1048576;
    public static final long MASK_RESOURCEID = 2097152;
    public static final long MASK_RESOURCEIDMATCHES = 4194304;
    public static final long MASK_SCROLLABLE = 16384;
    public static final long MASK_SELECTED = 262144;
    public static final long MASK_TEXT = 1;
    public static final long MASK_TEXTCONTAINS = 2;
    public static final long MASK_TEXTMATCHES = 4;
    public static final long MASK_TEXTSTARTSWITH = 8;
    private boolean _checkable;
    private boolean _checked;
    private String _className;
    private String _classNameMatches;
    private boolean _clickable;
    private String _description;
    private String _descriptionContains;
    private String _descriptionMatches;
    private String _descriptionStartsWith;
    private boolean _enabled;
    private boolean _focusable;
    private boolean _focused;
    private int _index;
    private int _instance;
    private boolean _longClickable;
    private long _mask;
    private String _packageName;
    private String _packageNameMatches;
    private String _resourceId;
    private String _resourceIdMatches;
    private boolean _scrollable;
    private boolean _selected;
    private String _text;
    private String _textContains;
    private String _textMatches;
    private String _textStartsWith;
    private Selector[] _childOrSiblingSelector = new Selector[0];
    private String[] _childOrSibling = new String[0];
    private final UiDevice device = UiDevice.getInstance(null);

    public UiSelector toUiSelector() {
        UiSelector s = new UiSelector();
        if ((getMask() & 1024) > 0) {
            s = s.checkable(isCheckable());
        }
        if ((getMask() & MASK_CHECKED) > 0) {
            s = s.checked(isChecked());
        }
        if ((getMask() & 16) > 0) {
            s = s.className(getClassName());
        }
        if ((getMask() & 32) > 0) {
            s = s.classNameMatches(getClassNameMatches());
        }
        if ((getMask() & MASK_CLICKABLE) > 0) {
            s = s.clickable(isClickable());
        }
        if ((getMask() & 64) > 0) {
            s = s.description(getDescription());
        }
        if ((getMask() & 128) > 0) {
            s = s.descriptionContains(getDescriptionContains());
        }
        if ((getMask() & 256) > 0) {
            s = s.descriptionMatches(getDescriptionMatches());
        }
        if ((getMask() & 512) > 0) {
            s = s.descriptionStartsWith(getDescriptionStartsWith());
        }
        if ((getMask() & MASK_ENABLED) > 0) {
            s = s.enabled(isEnabled());
        }
        if ((getMask() & MASK_FOCUSABLE) > 0) {
            s = s.focusable(isFocusable());
        }
        if ((getMask() & MASK_FOCUSED) > 0) {
            s = s.focused(isFocused());
        }
        if ((getMask() & MASK_INDEX) > 0) {
            s = s.index(getIndex());
        }
        if ((getMask() & MASK_INSTANCE) > 0) {
            s = s.instance(getInstance());
        }
        if ((getMask() & MASK_LONGCLICKABLE) > 0) {
            s = s.longClickable(isLongClickable());
        }
        if ((getMask() & MASK_PACKAGENAME) > 0) {
            s = s.packageName(getPackageName());
        }
        if ((getMask() & 1048576) > 0) {
            s = s.packageNameMatches(getPackageNameMatches());
        }
        if ((getMask() & MASK_RESOURCEID) > 0) {
            s = s.resourceId(getResourceId());
        }
        if ((getMask() & MASK_RESOURCEIDMATCHES) > 0) {
            s = s.resourceIdMatches(getResourceIdMatches());
        }
        if ((getMask() & MASK_SCROLLABLE) > 0) {
            s = s.scrollable(isScrollable());
        }
        if ((getMask() & MASK_SELECTED) > 0) {
            s = s.selected(isSelected());
        }
        if ((getMask() & 1) > 0) {
            s = s.text(getText());
        }
        if ((getMask() & 2) > 0) {
            s = s.textContains(getTextContains());
        }
        if ((getMask() & 8) > 0) {
            s = s.textStartsWith(getTextStartsWith());
        }
        if ((getMask() & 4) > 0) {
            s = s.textMatches(getTextMatches());
        }
        for (int i = 0; i < getChildOrSibling().length && i < getChildOrSiblingSelector().length; i++) {
            if (getChildOrSibling()[i].equalsIgnoreCase("child")) {
                s = s.childSelector(getChildOrSiblingSelector()[i].toUiSelector());
            } else if (getChildOrSibling()[i].equalsIgnoreCase("sibling")) {
                s = s.fromParent(getChildOrSiblingSelector()[i].toUiSelector());
            }
        }
        return s;
    }

    public BySelector toBySelector() {
        BySelector s = null;
        if ((getMask() & 1024) > 0) {
            s = By.checkable(isCheckable());
        }
        if ((getMask() & MASK_CHECKED) > 0) {
            if (s == null) {
                s = By.checked(isChecked());
            } else {
                s = s.checkable(isChecked());
            }
        }
        if ((getMask() & 16) > 0) {
            if (s == null) {
                s = By.clazz(getClassName());
            } else {
                s = s.clazz(getClassName());
            }
        }
        if ((getMask() & 32) > 0) {
            if (s == null) {
                s = By.clazz(Pattern.compile(getClassNameMatches()));
            } else {
                s = s.clazz(Pattern.compile(getClassNameMatches()));
            }
        }
        if ((getMask() & MASK_CLICKABLE) > 0) {
            if (s == null) {
                s = By.clickable(isClickable());
            } else {
                s = s.clickable(isClickable());
            }
        }
        if ((getMask() & 64) > 0) {
            if (s == null) {
                s = By.desc(getDescription());
            } else {
                s = s.desc(getDescription());
            }
        }
        if ((getMask() & 128) > 0) {
            if (s == null) {
                s = By.descContains(getDescriptionContains());
            } else {
                s = s.descContains(getDescriptionContains());
            }
        }
        if ((getMask() & 256) > 0) {
            if (s == null) {
                s = By.desc(Pattern.compile(getDescriptionMatches()));
            } else {
                s = s.desc(Pattern.compile(getDescriptionMatches()));
            }
        }
        if ((getMask() & 512) > 0) {
            if (s == null) {
                s = By.descStartsWith(getDescriptionStartsWith());
            } else {
                s = s.descStartsWith(getDescriptionStartsWith());
            }
        }
        if ((getMask() & MASK_ENABLED) > 0) {
            if (s == null) {
                s = By.enabled(isEnabled());
            } else {
                s = s.enabled(isEnabled());
            }
        }
        if ((getMask() & MASK_FOCUSABLE) > 0) {
            if (s == null) {
                s = By.focusable(isFocusable());
            } else {
                s = s.focusable(isFocusable());
            }
        }
        if ((getMask() & MASK_FOCUSED) > 0) {
            if (s == null) {
                s = By.focused(isFocused());
            } else {
                s = s.focused(isFocused());
            }
        }
        if ((getMask() & MASK_LONGCLICKABLE) > 0) {
            if (s == null) {
                s = By.longClickable(isLongClickable());
            } else {
                s = s.longClickable(isLongClickable());
            }
        }
        if ((getMask() & MASK_PACKAGENAME) > 0) {
            if (s == null) {
                s = By.pkg(getPackageName());
            } else {
                s = s.pkg(getPackageName());
            }
        }
        if ((getMask() & 1048576) > 0) {
            if (s == null) {
                s = By.pkg(Pattern.compile(getPackageNameMatches()));
            } else {
                s = s.pkg(Pattern.compile(getPackageNameMatches()));
            }
        }
        if ((getMask() & MASK_RESOURCEID) > 0) {
            if (s == null) {
                s = By.res(getResourceId());
            } else {
                s = s.res(getResourceId());
            }
        }
        if ((getMask() & MASK_RESOURCEIDMATCHES) > 0) {
            if (s == null) {
                s = By.res(Pattern.compile(getResourceIdMatches()));
            } else {
                s = s.res(Pattern.compile(getResourceIdMatches()));
            }
        }
        if ((getMask() & MASK_SCROLLABLE) > 0) {
            if (s == null) {
                s = By.scrollable(isScrollable());
            } else {
                s = s.scrollable(isScrollable());
            }
        }
        if ((getMask() & MASK_SELECTED) > 0) {
            if (s == null) {
                s = By.selected(isSelected());
            } else {
                s = s.selected(isSelected());
            }
        }
        if ((getMask() & 1) > 0) {
            if (s == null) {
                s = By.text(getText());
            } else {
                s = s.text(getText());
            }
        }
        if ((getMask() & 2) > 0) {
            if (s == null) {
                s = By.textContains(getTextContains());
            } else {
                s = s.textContains(getTextContains());
            }
        }
        if ((getMask() & 8) > 0) {
            if (s == null) {
                s = By.textStartsWith(getTextStartsWith());
            } else {
                s = s.textStartsWith(getTextStartsWith());
            }
        }
        if ((getMask() & 4) > 0) {
            if (s == null) {
                BySelector s2 = By.text(Pattern.compile(getTextMatches()));
                return s2;
            }
            return s.text(Pattern.compile(getTextMatches()));
        }
        return s;
    }

    public boolean checkBySelectorNull(Selector s) {
        return (s.getMask() & MASK_INDEX) > 0 || (s.getMask() & MASK_INSTANCE) > 0 || s.toBySelector() == null;
    }

    public UiObject2 toUiObject2() {
        if (checkBySelectorNull(this)) {
            return null;
        }
        UiObject2 obj2 = this.device.findObject(toBySelector());
        if (getChildOrSibling().length > 0) {
            return null;
        }
        return obj2;
    }

    public Selector deepSelector() {
        if (getChildOrSibling().length == 0) {
            return this;
        }
        return getChildOrSiblingSelector()[getChildOrSiblingSelector().length - 1];
    }

    public UiSelector toUiSelector(int instance) {
        Selector sel = deepSelector();
        int oldInstance = sel.getInstance();
        long oldMask = sel.getMask();
        sel.setMask(sel.getMask() | MASK_INSTANCE);
        sel.setInstance(instance);
        UiSelector uiSelector = toUiSelector();
        sel.setInstance(oldInstance);
        sel.setMask(oldMask);
        return uiSelector;
    }

    public String getText() {
        return this._text;
    }

    public void setText(String text) {
        this._text = text;
    }

    public String getClassName() {
        return this._className;
    }

    public void setClassName(String className) {
        this._className = className;
    }

    public String getDescription() {
        return this._description;
    }

    public void setDescription(String description) {
        this._description = description;
    }

    public String getTextContains() {
        return this._textContains;
    }

    public void setTextContains(String _textContains) {
        this._textContains = _textContains;
    }

    public String getTextMatches() {
        return this._textMatches;
    }

    public void setTextMatches(String _textMatches) {
        this._textMatches = _textMatches;
    }

    public String getTextStartsWith() {
        return this._textStartsWith;
    }

    public void setTextStartsWith(String _textStartsWith) {
        this._textStartsWith = _textStartsWith;
    }

    public String getClassNameMatches() {
        return this._classNameMatches;
    }

    public void setClassNameMatches(String _classNameMatches) {
        this._classNameMatches = _classNameMatches;
    }

    public String getDescriptionContains() {
        return this._descriptionContains;
    }

    public void setDescriptionContains(String _descriptionContains) {
        this._descriptionContains = _descriptionContains;
    }

    public String getDescriptionMatches() {
        return this._descriptionMatches;
    }

    public void setDescriptionMatches(String _descriptionMatches) {
        this._descriptionMatches = _descriptionMatches;
    }

    public String getDescriptionStartsWith() {
        return this._descriptionStartsWith;
    }

    public void setDescriptionStartsWith(String _descriptionStartsWith) {
        this._descriptionStartsWith = _descriptionStartsWith;
    }

    public boolean isCheckable() {
        return this._checkable;
    }

    public void setCheckable(boolean _checkable) {
        this._checkable = _checkable;
    }

    public boolean isChecked() {
        return this._checked;
    }

    public void setChecked(boolean _checked) {
        this._checked = _checked;
    }

    public boolean isClickable() {
        return this._clickable;
    }

    public void setClickable(boolean _clickable) {
        this._clickable = _clickable;
    }

    public boolean isScrollable() {
        return this._scrollable;
    }

    public void setScrollable(boolean _scrollable) {
        this._scrollable = _scrollable;
    }

    public boolean isLongClickable() {
        return this._longClickable;
    }

    public void setLongClickable(boolean _longClickable) {
        this._longClickable = _longClickable;
    }

    public boolean isEnabled() {
        return this._enabled;
    }

    public void setEnabled(boolean _enabled) {
        this._enabled = _enabled;
    }

    public boolean isFocusable() {
        return this._focusable;
    }

    public void setFocusable(boolean _focusable) {
        this._focusable = _focusable;
    }

    public boolean isFocused() {
        return this._focused;
    }

    public void setFocused(boolean _focused) {
        this._focused = _focused;
    }

    public boolean isSelected() {
        return this._selected;
    }

    public void setSelected(boolean _selected) {
        this._selected = _selected;
    }

    public String getPackageName() {
        return this._packageName;
    }

    public void setPackageName(String _packageName) {
        this._packageName = _packageName;
    }

    public String getPackageNameMatches() {
        return this._packageNameMatches;
    }

    public void setPackageNameMatches(String _packageNameMatches) {
        this._packageNameMatches = _packageNameMatches;
    }

    public String getResourceId() {
        return this._resourceId;
    }

    public void setResourceId(String _resourceId) {
        this._resourceId = _resourceId;
    }

    public String getResourceIdMatches() {
        return this._resourceIdMatches;
    }

    public void setResourceIdMatches(String _resourceIdMatches) {
        this._resourceIdMatches = _resourceIdMatches;
    }

    public int getIndex() {
        return this._index;
    }

    public void setIndex(int _index) {
        this._index = _index;
    }

    public int getInstance() {
        return this._instance;
    }

    public void setInstance(int _instance) {
        this._instance = _instance;
    }

    public long getMask() {
        return this._mask;
    }

    public void setMask(long _mask) {
        this._mask = _mask;
    }

    public Selector[] getChildOrSiblingSelector() {
        return this._childOrSiblingSelector;
    }

    public void setChildOrSiblingSelector(Selector[] _childOrSiblingSelector) {
        this._childOrSiblingSelector = _childOrSiblingSelector;
    }

    public String[] getChildOrSibling() {
        return this._childOrSibling;
    }

    public void setChildOrSibling(String[] _childOrSibling) {
        this._childOrSibling = _childOrSibling;
    }
}